package com.kavadani.dialogs;

import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;
import com.kavadani.profiles.R;

public class ProgressDlg {
	
	private static ProgressDialog _dlgProgress = null;
	
	public static void show(Context context) {
		ProgressDlg.close();
		// --- 
		_dlgProgress = new ProgressDialog(context);
		_dlgProgress.setOnKeyListener(new DialogInterface.OnKeyListener() {
			public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
				switch (keyCode) {
				case KeyEvent.KEYCODE_BACK:
					dialog.cancel();
					return true;
				}
				return true;
			}
		});
		_dlgProgress.setMessage(context.getString(R.string.message_please_wait));
		_dlgProgress.show();
	}
	
	public static void setText(String message) {
		if(_dlgProgress == null || message == null) { return; }
		_dlgProgress.setMessage(message);
	}
	
	public static void close() {
		if(_dlgProgress != null) {
			if(_dlgProgress.isShowing()) { _dlgProgress.cancel(); }
			
			_dlgProgress = null;
		}
	}
}
